home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / QuickTime / QuickTime 3 Interfaces & Libs / QTDevWin / CIncludes / GXMath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-21  |  9.2 KB  |  316 lines  |  [TEXT/dosa]

  1. /*
  2.      File:        GXMath.h
  3.  
  4.      Contains:    QuickDraw GX math routine interfaces.
  5.  
  6.      Version:    Technology:    Quickdraw GX 1.1
  7.                  Release:    QuickTime 3.0
  8.  
  9.      Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __GXMATH__
  19. #define __GXMATH__
  20.  
  21. #ifndef __CONDITIONALMACROS__
  22. #include <ConditionalMacros.h>
  23. #endif
  24. #ifndef __MACTYPES__
  25. #include <MacTypes.h>
  26. #endif
  27. #ifndef __FIXMATH__
  28. #include <FixMath.h>
  29. #endif
  30.  
  31.  
  32.  
  33. #if PRAGMA_ONCE
  34. #pragma once
  35. #endif
  36.  
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40.  
  41. #if PRAGMA_IMPORT
  42. #pragma import on
  43. #endif
  44.  
  45. #if PRAGMA_STRUCT_ALIGN
  46.     #pragma options align=mac68k
  47. #elif PRAGMA_STRUCT_PACKPUSH
  48.     #pragma pack(push, 2)
  49. #elif PRAGMA_STRUCT_PACK
  50.     #pragma pack(2)
  51. #endif
  52.  
  53. #if defined(__MWERKS__) && TARGET_CPU_68K
  54.     #pragma push
  55.     #pragma pointers_in_D0
  56. #endif
  57.  
  58.  
  59.  
  60. struct gxPoint {
  61.     Fixed                             x;
  62.     Fixed                             y;
  63. };
  64. typedef struct gxPoint                    gxPoint;
  65.  
  66. typedef unsigned short                     gxColorValue;
  67.  
  68. struct gxPolar {
  69.     Fixed                             radius;
  70.     Fixed                             angle;
  71. };
  72. typedef struct gxPolar                    gxPolar;
  73.  
  74. struct gxMapping {
  75.     Fixed                             map[3][3];
  76. };
  77. typedef struct gxMapping                gxMapping;
  78.  
  79. #define    gxColorValue1            ((gxColorValue) 0x0000FFFF)
  80. #define  gxPositiveInfinity        ((long) 0x7FFFFFFFL)
  81. #define    gxNegativeInfinity        ((long) 0x80000000L)
  82.  
  83. EXTERN_API_C( gxMapping *)
  84. CopyToMapping                    (gxMapping *            target,
  85.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0031, 0xA832);
  86.  
  87. EXTERN_API_C( gxMapping *)
  88. InvertMapping                    (gxMapping *            target,
  89.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0032, 0xA832);
  90.  
  91. EXTERN_API_C( gxMapping *)
  92. MapMapping                        (gxMapping *            target,
  93.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0033, 0xA832);
  94.  
  95. EXTERN_API_C( gxMapping *)
  96. MoveMapping                        (gxMapping *            target,
  97.                                  Fixed                     hOffset,
  98.                                  Fixed                     vOffset)                            THREEWORDINLINE(0x303C, 0x0034, 0xA832);
  99.  
  100. EXTERN_API_C( gxMapping *)
  101. MoveMappingTo                    (gxMapping *            target,
  102.                                  Fixed                     hPosition,
  103.                                  Fixed                     vPosition)                            THREEWORDINLINE(0x303C, 0x0035, 0xA832);
  104.  
  105. EXTERN_API_C( gxMapping *)
  106. NormalizeMapping                (gxMapping *            target)                                THREEWORDINLINE(0x303C, 0x0036, 0xA832);
  107.  
  108. EXTERN_API_C( gxMapping *)
  109. RotateMapping                    (gxMapping *            target,
  110.                                  Fixed                     angle,
  111.                                  Fixed                     xCenter,
  112.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x0037, 0xA832);
  113.  
  114. EXTERN_API_C( gxMapping *)
  115. ScaleMapping                    (gxMapping *            target,
  116.                                  Fixed                     hFactor,
  117.                                  Fixed                     vFactor,
  118.                                  Fixed                     xCenter,
  119.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x0038, 0xA832);
  120.  
  121. EXTERN_API_C( gxMapping *)
  122. ResetMapping                    (gxMapping *            target)                                THREEWORDINLINE(0x303C, 0x0039, 0xA832);
  123.  
  124. EXTERN_API_C( gxMapping *)
  125. SkewMapping                        (gxMapping *            target,
  126.                                  Fixed                     skewX,
  127.                                  Fixed                     skewY,
  128.                                  Fixed                     xCenter,
  129.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x003A, 0xA832);
  130.  
  131. EXTERN_API_C( void )
  132. MapPoints                        (const gxMapping *        source,
  133.                                  long                     count,
  134.                                  gxPoint                 vector[])                                THREEWORDINLINE(0x303C, 0x003B, 0xA832);
  135.  
  136. EXTERN_API_C( short )
  137. FirstBit                        (unsigned long             x)                                    THREEWORDINLINE(0x303C, 0x003C, 0xA832);
  138.  
  139. EXTERN_API_C( short )
  140. WideScale                        (const wide *            source)                                THREEWORDINLINE(0x303C, 0x003D, 0xA832);
  141.  
  142. EXTERN_API_C( short )
  143. LinearRoot                        (Fixed                     first,
  144.                                  Fixed                     last,
  145.                                  Fract                     t[])                                    THREEWORDINLINE(0x303C, 0x003E, 0xA832);
  146.  
  147. EXTERN_API_C( short )
  148. QuadraticRoot                    (Fixed                     first,
  149.                                  Fixed                     control,
  150.                                  Fixed                     last,
  151.                                  Fract                     t[])                                    THREEWORDINLINE(0x303C, 0x003F, 0xA832);
  152.  
  153. EXTERN_API_C( gxPoint *)
  154. PolarToPoint                    (const gxPolar *        ra,
  155.                                  gxPoint *                xy)                                    THREEWORDINLINE(0x303C, 0x0040, 0xA832);
  156.  
  157. EXTERN_API_C( gxPolar *)
  158. PointToPolar                    (const gxPoint *        xy,
  159.                                  gxPolar *                ra)                                    THREEWORDINLINE(0x303C, 0x0041, 0xA832);
  160.  
  161. EXTERN_API_C( Fract )
  162. FractCubeRoot                    (Fract                     source)                                THREEWORDINLINE(0x303C, 0x0042, 0xA832);
  163.  
  164. EXTERN_API_C( Fract )
  165. FractDivide                        (Fract                     dividend,
  166.                                  Fract                     divisor)                            THREEWORDINLINE(0x303C, 0x0043, 0xA832);
  167.  
  168. EXTERN_API_C( Fract )
  169. FractMultiply                    (Fract                     multiplicand,
  170.                                  Fract                     multiplier)                            THREEWORDINLINE(0x303C, 0x0044, 0xA832);
  171.  
  172. EXTERN_API_C( Fract )
  173. FractSineCosine                    (Fixed                     degrees,
  174.                                  Fract *                cosine)                                THREEWORDINLINE(0x303C, 0x0045, 0xA832);
  175.  
  176. EXTERN_API_C( Fract )
  177. FractSquareRoot                    (Fract                     source)                                THREEWORDINLINE(0x303C, 0x0046, 0xA832);
  178.  
  179. EXTERN_API_C( Fixed )
  180. FixedDivide                        (Fixed                     dividend,
  181.                                  Fixed                     divisor)                            THREEWORDINLINE(0x303C, 0x0047, 0xA832);
  182.  
  183. EXTERN_API_C( Fixed )
  184. FixedMultiply                    (Fixed                     multiplicand,
  185.                                  Fixed                     multiplier)                            THREEWORDINLINE(0x303C, 0x0048, 0xA832);
  186.  
  187. /* This next call is (source * multiplier / divisor) -- it avoids underflow, overflow by using wides */
  188. EXTERN_API_C( long )
  189. MultiplyDivide                    (long                     source,
  190.                                  long                     multiplier,
  191.                                  long                     divisor)                            THREEWORDINLINE(0x303C, 0x0049, 0xA832);
  192.  
  193. EXTERN_API_C( unsigned long )
  194. Magnitude                        (long                     deltaX,
  195.                                  long                     deltaY)                                THREEWORDINLINE(0x303C, 0x004A, 0xA832);
  196.  
  197. EXTERN_API_C( long )
  198. VectorMultiplyDivide            (long                     count,
  199.                                  const long *            vector1,
  200.                                  long                     step1,
  201.                                  const long *            vector2,
  202.                                  long                     step2,
  203.                                  long                     divisor)                            THREEWORDINLINE(0x303C, 0x004B, 0xA832);
  204.  
  205.  
  206.  
  207.  
  208. /* wide operations are defined within FixMath.h only for PowerPC */
  209. #if !TARGET_CPU_PPC
  210. EXTERN_API_C( wide *)
  211. WideAdd                            (wide *                    target,
  212.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x004C, 0xA832);
  213.  
  214. EXTERN_API_C( short )
  215. WideCompare                        (const wide *            target,
  216.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x004D, 0xA832);
  217.  
  218. EXTERN_API_C( wide *)
  219. WideNegate                        (wide *                    target)                                THREEWORDINLINE(0x303C, 0x004E, 0xA832);
  220.  
  221. EXTERN_API_C( wide *)
  222. WideShift                        (wide *                    target,
  223.                                  long                     shift)                                THREEWORDINLINE(0x303C, 0x004F, 0xA832);
  224.  
  225. EXTERN_API_C( unsigned long )
  226. WideSquareRoot                    (const wide *            source)                                THREEWORDINLINE(0x303C, 0x0050, 0xA832);
  227.  
  228. EXTERN_API_C( wide *)
  229. WideSubtract                    (wide *                    target,
  230.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x0051, 0xA832);
  231.  
  232. EXTERN_API_C( wide *)
  233. WideMultiply                    (long                     multiplicand,
  234.                                  long                     multiplier,
  235.                                  wide *                    target)                                THREEWORDINLINE(0x303C, 0x0052, 0xA832);
  236.  
  237. /* returns the quotient */
  238. EXTERN_API_C( long )
  239. WideDivide                        (const wide *            dividend,
  240.                                  long                     divisor,
  241.                                  long *                    remainder)                            THREEWORDINLINE(0x303C, 0x0053, 0xA832);
  242.  
  243. /* quotient replaces dividend */
  244. EXTERN_API_C( wide *)
  245. WideWideDivide                    (wide *                    dividend,
  246.                                  long                     divisor,
  247.                                  long *                    remainder)                            THREEWORDINLINE(0x303C, 0x0055, 0xA832);
  248.  
  249. #endif  /*  !TARGET_CPU_PPC */
  250.  
  251.  
  252.  
  253. EXTERN_API_C( wide *)
  254. VectorMultiply                    (long                     count,
  255.                                  const long *            vector1,
  256.                                  long                     step1,
  257.                                  const long *            vector2,
  258.                                  long                     step2,
  259.                                  wide *                    dot)                                THREEWORDINLINE(0x303C, 0x0054, 0xA832);
  260.  
  261. EXTERN_API_C( unsigned long )
  262. RandomBits                        (long                     count,
  263.                                  long                     focus)                                THREEWORDINLINE(0x303C, 0x0056, 0xA832);
  264.  
  265. EXTERN_API_C( void )
  266. SetRandomSeed                    (const wide *            seed)                                THREEWORDINLINE(0x303C, 0x0057, 0xA832);
  267.  
  268. EXTERN_API_C( wide *)
  269. GetRandomSeed                    (wide *                    seed)                                THREEWORDINLINE(0x303C, 0x0058, 0xA832);
  270.  
  271.  
  272. #define FixedRound(a)        ((short)((Fixed)(a) + fixed1/2 >> 16))
  273. #define FixedSquareRoot(a)    ((Fixed)FractSquareRoot(a) + 64 >> 7)
  274. #define FixedTruncate(a)        ((short)((Fixed)(a) >> 16))
  275. #define FixedToFract(a)        ((Fract)(a) << 14)
  276. #define FractToFixed(a)        ((Fixed)(a) + 8192L >> 14)
  277. #define FixedToInt(a)       ((short)((Fixed)(a) + fixed1/2 >> 16))
  278. #define IntToFixed(a)       ((Fixed)(a) << 16)
  279. #define FixedToFloat(a)     ((float)(a) / fixed1)
  280. #define FloatToFixed(a)         ((Fixed)((float)(a) * fixed1))
  281. #define FractToFloat(a)     ((float)(a) / fract1)
  282. #define FloatToFract(a)     ((Fract)((float)(a) * fract1))
  283. #define ColorToFract(a)     (((Fract) (a) << 14) + ((Fract)(a) + 2 >> 2))
  284. #define FractToColor(a)     ((gxColorValue) ((a) - ((a) >> 16) + 8191 >> 14))
  285. #ifndef ff    /* ff is already defined on some platforms */
  286. #define ff(a)               IntToFixed(a)
  287. #define fl(a)               FloatToFixed(a)
  288. #endif
  289.  
  290.  
  291. #if defined(__MWERKS__) && TARGET_CPU_68K
  292.     #pragma pop
  293. #endif
  294.  
  295.  
  296. #if PRAGMA_STRUCT_ALIGN
  297.     #pragma options align=reset
  298. #elif PRAGMA_STRUCT_PACKPUSH
  299.     #pragma pack(pop)
  300. #elif PRAGMA_STRUCT_PACK
  301.     #pragma pack()
  302. #endif
  303.  
  304. #ifdef PRAGMA_IMPORT_OFF
  305. #pragma import off
  306. #elif PRAGMA_IMPORT
  307. #pragma import reset
  308. #endif
  309.  
  310. #ifdef __cplusplus
  311. }
  312. #endif
  313.  
  314. #endif /* __GXMATH__ */
  315.  
  316.